import { request } from 'umi';
import { ProgramDetail } from '@/data-type'
import { BaseService } from './baseService';
class ProgramDetailServiceImpl implements BaseService<ProgramDetail> {
  async queryList(options?: { [key: string]: any; } | undefined): Promise<{ data: ProgramDetail[]; }> {
    let retData = {
      data: [
        {
          id: 123456,
          programId: 123456,
          eqName: "塔机1号",
          eqModel: "tjxh001",
          status: "正常",
          startDate: new Date('2021-10-12'),
          endDate: new Date('2022-7-1'),
        },
        {
          id: 1234561,
          programId: 123456,
          eqName: "塔机1号",
          eqModel: "tjxh001",
          status: "正常",
          startDate: new Date('2021-10-12'),
          endDate: new Date('2022-7-1'),
        }
      ],
    }
    // debugger
    // if (options?.programId) {
    //   retData = { data: retData.data.filter((data, i, retData) => data.programId == options.programId) }
    // }
    let ret: ProgramDetail[] = [];
    await request("/program-detail/query_list", {
      method: "POST",
      data: {
        ...options
      }
    }).then(response => {
      ret = response.data;
    })
    return Promise.resolve({ data: ret });
  }
  async deleteOne(id: number): Promise<boolean> {
    console.log("need delete id is", id);
    await request("/program-detail/delete_one", {
      method: "DELETE",
      data: {
        id,
      }
    }).then(response => {
      // ret = response.data;
    })
    return Promise.resolve(true);
  }
  async updateOne(entity: ProgramDetail): Promise<boolean> {
    console.log("need update id is", entity);
    await request("/program-detail/update_one", {
      method: "PUT",
      data: {
        ...entity
      }
    }).then(response => {
      // ret = response.data;
    })
    return Promise.resolve(true);
  }
  async save(entity: ProgramDetail): Promise<boolean> {
    console.log("保存成功");
    await request("/program-detail/save_one", {
      method: "POST",
      data: {
        ...entity
      }
    }).then(response => {
      // ret = response.data;
    })
    return Promise.resolve(true);
  }
}
export const ProgramDetailService = new ProgramDetailServiceImpl();